﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TestRequestResponseMessages;
using PServiceBus.MessageProxy;
using PServiceBus.Transports;

namespace TestRequestResponseClient {

    [ESBProxyService]
    public interface IRequestResponseService {

        [ESBTransport(typeof(TcpTransport))]
        [ESBTransportParam("Port", "2222")]
        [ESBTransportParam("IPAddress", "127.0.0.1")]
        [ESBRequest(typeof(Request), isRequestClass: true)]
        Response Send(Request request);

    }

    class Program {
        static void Main(string[] args) {

            ProxyService.Start();

            var service = ProxyService.Create<IRequestResponseService>();

            Console.WriteLine("Press enter to send request. Type exit to end client");

            while (true) {
                var text = Console.ReadLine();
                if (text.ToLower() == "exit") break;
                var response = service.Send(new Request() { 
                    Data = String.Format("Message: {0}", Guid.NewGuid())
                });
                if (response != null)
                    Console.WriteLine("Received response [ID: {0}, Message: {1}, Success: {2}]",
                        response.ESBCorrelationID, response.Message, response.Success);
                else
                    Console.WriteLine("Could not process request");
            }

            ProxyService.Shutdown();
        }
    }
}
